package fschmidt.util.servlet;

import org.eclipse.jetty.servlet.DefaultServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;


public final class JarDefaultServlet extends DefaultServlet {
	private static final Logger logger = LoggerFactory.getLogger(JarDefaultServlet.class);

	private static final long built;
	static {
		try {
			built = new Date(ClassLoader.getSystemResource("fschmidt/util/servlet/JarDefaultServlet.class").openConnection().getLastModified()).getTime()/1000*1000;
		} catch(IOException e) {
			logger.error("",e);
			throw new RuntimeException(e);
		}
	}

	protected void doGet(HttpServletRequest request,HttpServletResponse response)
		throws ServletException, IOException
	{
		if( built <= request.getDateHeader("If-Modified-Since") ) {
			response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
			return;
		}
		super.doGet(request,response);
	}
}
